

#ifndef VIEWS_UTILITIES_H__
#define VIEWS_UTILITIES_H__

#include <stdint.h>


typedef struct
{
    int16_t x;
    int16_t y;

    bool    is_short_hold ;
    int16_t index;

    void*   pvalue;
}views_util_value_t;

// 界面使用的标识变量
extern uint32_t m_flag_of_view_share; 

#define FLAG_ALL()         m_flag_of_view_share = 0xfffffffful
#define FLAG_SETB(n)       m_flag_of_view_share |= (1 << n)
#define FLAG_RESETB(n)     m_flag_of_view_share &= ~(1 << n)
#define FLAG_TOGGLEB(n)    m_flag_of_view_share ^= (1 << n)
#define FLAG_GETB(n)    (m_flag_of_view_share & (1 << n))
#define FLAG_INITB(n)      m_flag_of_view_share = n  
#define FLAG_CLEAR()          m_flag_of_view_share = 0
#define FLAG_INC()          m_flag_of_view_share ++;

/*
    battery level to bar 
*/
static inline int views_util_battery_level_to_bar(uint8_t percent)
{
    if( percent >= 80 )
    {
        return 4;
    }

    return percent / 20;
}

static inline int views_util_battery_level_to_6bars(uint8_t percent)
{
    if( percent >= 80 )
    {
        return 4;
    }
    return percent / 20; 
}

static inline int views_util_brightness_level_to_6bars(uint8_t percent)
{
    if( percent >= 80 )
    {
        return 5;
    }
    
    return percent / 16;
}
static inline int views_util_brightness_level_to_3bars(uint8_t percent)
{
    if( percent < 33 )
    {
        return 0;
    }
    else if( percent <= 60 )
    {
        return 1;
    }
    else
    {
        return 2; 
    }
}


void views_util_fsm_init(int32_t min, int32_t max, int32_t cur);
int32_t views_util_fsm_get(void);
void views_util_fsm_set(int32_t val);
void views_util_fsm_reset(void);
void views_util_fsm_toggle(void);
void views_util_fsm_inc(void);
void views_util_fsm_dec(void); 


extern views_util_value_t m_views_util_values;

#define VALUES_SET( FIELD, VALUE )  m_views_util_values.FIELD = VALUE 
#define VALUES_SET_2( FIELD_1, FIELD_2, VALUE_1, VALUE_2 ) m_views_util_values.FIELD_1 = VALUE_1; m_views_util_values.FIELD_2 = VALUE_2
#define VALUES_GET( FIELD )  (m_views_util_values.FIELD )

#define VALUES_SETPTR( FIELD, VALUE ) m_views_util_values.FIELD = (void*)VALUE
#define VALUES_GETPTR( FIELD ) (m_views_util_values.FIELD)



void views_util_set_axis_x(int16_t x);
void views_util_set_axis_y(int16_t y);

extern uint16_t share_text[20];
#endif

